/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cl.virtualbook.persistencia;

import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JOptionPane;

/**
 *
 * @author jonathan briones
 */
public class ConexionMySql {
    
    private String bd = "virtualbook";
    private String usuario = "root";
    private String clave = "qwerty";
    private String url = "jdbc:mysql://localhost:3306/"+bd+","+usuario+","+clave;
    private Connection conn;
    
    public ConexionMySql(){ 
        try{
            Class.forName("com.mysql.jdbc.Driver");
        }
        catch(Exception ex){
            JOptionPane.showConfirmDialog(null, "Error Con" +ex);
        }
    }
    
    public void conectar(){
        try{
            this.conn = DriverManager.getConnection(url);
        }
        catch(Exception ex){
            JOptionPane.showConfirmDialog(null, "Error Con" +ex);
        }
    }
    
    public Connection getConexion(){
        return this.conn;
    }
    
    public void desconectar(){
        try{
            conn.close();
        }
        catch(Exception ex){
            JOptionPane.showConfirmDialog(null, "Error Con" +ex);
        }
    }
}
